package com.csii.pos.scaleplan;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.adhoc.util.ConvertUtils;
import com.csii.adhoc.controller.BaseController;
import com.csii.pos.dto.accountlimits.AccountLimitsReq;
import com.csii.pos.dto.accountlimits.AccountReq;
import com.csii.pos.dto.accountlimits.AccountLimitsRes;
import com.csii.pos.dto.accountlimits.AccountRes;
import com.csii.pos.rpc.Paging;
import com.csii.pos.scaleplan.service.IIfbScalePlanService;
import com.csii.pos.service.accountlimits.AccountLimitsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 接收通知
 * @author: liuzhonghua
 * @create: 2021-7-22
 */
@RestController
@Slf4j
public class AccountLimitsController extends BaseController<IfbScalePlan, IIfbScalePlanService> implements AccountLimitsService {
    @Autowired
    private IIfbScalePlanService ifbScalePlanService;


    @Override
    public AccountLimitsRes queryAcctLimtAmt(AccountLimitsReq accountLimitsReq) {
        Page<IfbScalePlan> page = new Page<>(accountLimitsReq.getPageNo(),accountLimitsReq.getPageSize());
        IPage<IfbScalePlan> list = ifbScalePlanService.page(page);
        AccountLimitsRes accountLimitsVos = changeVo(list,accountLimitsReq);
        return accountLimitsVos;
    }

    @Override
    public AccountRes queryIfbScalePlan(AccountReq accountReq) {

        QueryWrapper<IfbScalePlan> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(accountReq.getIfbPlanDate())){
            queryWrapper.like("IFB_PLAN_DATE", accountReq.getIfbPlanDate());
        }
        if (!StringUtils.isEmpty(accountReq.getIfbToolType())){
            queryWrapper.eq("IFB_TOOL_TYPE", accountReq.getIfbToolType());
        }
        if ((!StringUtils.isEmpty(accountReq.getLqdtSltFlag()))){
            queryWrapper.eq("LQDT_SLT_FLAG", accountReq.getLqdtSltFlag());
        }
        IfbScalePlan one = ifbScalePlanService.getOne(queryWrapper);
        BigDecimal unexecPlanAmt = one.getUnexecPlanAmt();
        AccountRes accountRes = new AccountRes();

        return accountRes;
    }

    /**
     * @description: 转换为需要的返回值
     * @param: AccountLimitsRes
     * @return:  IPage<IfbScalePlan>
     * @author liuzhonghua
     * @date:  2021-7-22
     */
    private AccountLimitsRes changeVo(IPage<IfbScalePlan> list,AccountLimitsReq accountLimitsReq){
        //返回的list
        List<AccountLimitsVo> lists = new ArrayList<>();
        //循环存入数据
        for (IfbScalePlan c:list.getRecords()) {
            AccountLimitsVo accountLimitsVo = ConvertUtils.convert(AccountLimitsVo.class, c);
//            accountLimitsVo.setNewPlanAmt(c.getApprPlanAmt());
//            accountLimitsVo.setFinishedDt(c.getCompleteDay());
//            accountLimitsVo.setStockBlcAmt(Double.valueOf(c.getIfbScaleBlc()));
            lists.add(accountLimitsVo);
        }

        AccountLimitsRes accountRes = ConvertUtils.convert(AccountLimitsRes.class, accountLimitsReq);

        accountRes.setData(lists);
        accountRes.setCode("200");
        return accountRes;
    }
}






